
package com.probiz.estore.common.model.catalog;

import com.probiz.estore.common.model.catalog.base.VirtualCategoryTbl;
import org.apache.commons.lang.StringUtils;

/**
 * Model class for VirtualCategory. Add not database mapped fileds in this
 * class. 专场目录
 */
public class VirtualCategory extends VirtualCategoryTbl {
	
	public final static Short STATUS_ACTIVE = (short) 1;
    public final static Short STATUS_INACTIVE = (short) 0;
    public final static Integer SORTORDER_DEFAULT_VALUE = new Integer("9999");

    public final static Short TYPE_PRODUCT = (short) 1;//商品专场
    public final static Short TYPE_LINK = (short) 2; //链接类型

	/**
	 * Default Empty Constructor for class VirtualCategory
	 */
	public VirtualCategory() {
		super();
	}

	/**
	 * Default Key Fields Constructor for class VirtualCategory
	 * 
	 * @param in_categoryId
	 *            目录id
	 */
	public VirtualCategory(Integer in_categoryId) {
		super(in_categoryId);
	}

	/**
	 * 定义实体的业务名
	 * 
	 * @return 实体业务名
	 */
	public String getVirtualCategoryName() {
		if (categoryId == null)
			return "";
		else
			// 返回一个指定有业务意义的属性值;
			// 如：product的VO就用product.productName
			return this.categoryName;
	}


	/**
	 * 获取完整的目录路径名 例：主页>电器专场>冰箱专场>海尔冰箱专场
	 * 
	 * @return 完整的目录路径名
	 */
	public String getFullCategoryPathName() {
		if (StringUtils.isNotBlank(getParentFullCategoryPathName())) {
			return getParentFullCategoryPathName() + ">" + getCategoryName();
		} else {
			return getCategoryName();
		}
	}

	/**
	 * 获取简单的目录路径名(不包含根) 例：电器专场>冰箱专场>海尔冰箱专场
	 * 
	 * @return 简单的目录路径名(不包含根)
	 */
	public String getSimpleCategoryPathName() {
		StringBuffer categoryPathNameBuffer = new StringBuffer(100);
		VirtualCategory parentCategory = this.getParent();
		while (parentCategory != null && parentCategory.getCategoryId() != 1) {
			categoryPathNameBuffer.insert(0, ">");
			categoryPathNameBuffer.insert(0, parentCategory.getCategoryName());
			parentCategory = parentCategory.getParent();
		}
		String categoryPathName = categoryPathNameBuffer.toString();
		if (!StringUtils.isEmpty(categoryPathName))
			categoryPathName = categoryPathName.substring(0, categoryPathName
					.length() - 1);
		if (StringUtils.isBlank(categoryPathName)) {
			return getCategoryName();
		} else {
			return categoryPathName + ">" + getCategoryName();
		}
	}

	/**
	 * 获取父目录完整的目录路径名 例：主页>电器专场>冰箱专场
	 * 
	 * @return 父目录完整的目录路径名
	 */
	public String getParentFullCategoryPathName() {
		StringBuffer categoryPathNameBuffer = new StringBuffer(100);
		VirtualCategory parentCategory = this.getParent();
		while (parentCategory != null) {
			categoryPathNameBuffer.insert(0, ">");
			categoryPathNameBuffer.insert(0, parentCategory.getCategoryName());
			parentCategory = parentCategory.getParent();
		}
		String categoryPathName = categoryPathNameBuffer.toString();
		if (!StringUtils.isEmpty(categoryPathName))
			categoryPathName = categoryPathName.substring(0, categoryPathName
					.length() - 1);
		return categoryPathName;
	}

}
